package com.kaifamiao.list;

import java.util.*;

// 了解用 Enumeration 迭代 集合
public class VectorTest2 {

    public static void main(String[] args) {

        Vector<String> vector = new Vector<>();
        System.out.println( "capacity: " + vector.capacity() + ", size: " + vector.size() );
        vector.add( "吉吉国王" );
        vector.add( "毛毛" );
        vector.addElement( "翠花" );
        vector.addAll( 2 , List.of( "熊大", "熊二" ) );

        Enumeration<String> x = vector.elements();

        while ( x.hasMoreElements() ) {
            String name = x.nextElement();
            System.out.println( name );
        }

        System.out.println( x.hasMoreElements() ); // false

        x = vector.elements();
        // 从 Java 9 开始 Enumeration 中增加了 asIterator 方法
        Iterator<String> it = x.asIterator();
        while( it.hasNext() ) {
            System.out.println( it.next() );
        }

    }

}
